package com.ThreadTest.locks;

import java.util.concurrent.CountDownLatch;

/**
 * @Author YongQiang
 * @Date 2021/2/25 16:31
 * @Version 1.0
 */
public class Volatiles {
    private static volatile int num = 0;


    private static CountDownLatch countDownLatch=new CountDownLatch(3);

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 3; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int j = 0; j < 1000; j++) {
                        num++;
                    }
                    countDownLatch.countDown();
                }
            }).start();
        }

        countDownLatch.await();
        System.out.println(num);
    }
}
